<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>扩容</title>
</head>

<body>
  <script>
    window.addEventListener('message', function (event) {
      var regName = event.data.regName;
      if (event.data.type === 'setItem') {
        try {
          localStorage.setItem(event.data.namespace, event.data.data);
          window.parent.postMessage(
            { type: 'setItemSuccessCallback', regName: regName, data: event.data.data },
            event.data.origin
          );
        } catch (err) {
          window.parent.postMessage(
            { type: 'setItemFailCallback', regName: regName, data: err },
            event.data.origin
          );
        }
      }
      else if (event.data.type === 'getItem') {
        try {
          const data = localStorage.getItem(event.data.namespace);
          window.parent.postMessage(
            { type: 'getItemSuccessCallback', regName: regName, data: data },
            event.data.origin
          );
        } catch (err) {
          window.parent.postMessage(
            { type: 'getItemFailCallback', regName: regName, data: err },
            event.data.origin
          );
        }
      }
      else if (event.data.type === 'removeItem') {
        try {
          localStorage.removeItem(event.data.namespace);
          window.parent.postMessage(
            { type: 'removeItemSuccessCallback', regName: regName },
            event.data.origin
          );
        } catch (err) {
          window.parent.postMessage(
            { type: 'removeItemFailCallback', regName: regName, data: err },
            event.data.origin
          );
        }
      }
    }, false);
  </script>
</body>

</html>